import { _decorator, Button, EPhysics2DDrawFlags, PhysicsSystem2D } from 'cc';
import CharacterManageSingle from '../character/CharacteManageSingle';
import FontSingle from '../game/FontSingle';
import { GameScene } from '../game/GameScene';
import LevelPO from '../game/level/LevelPO';
import { FontBubblePool } from '../libs/component/font/FontBubblePool';
const { ccclass, property } = _decorator;

@ccclass('TestScene')
export class TestScene extends GameScene {
    /****************************************************************************************************************
     *Readonly 常量
     ****************************************************************************************************************/

    /****************************************************************************************************************
     *Property 定义变量
     ****************************************************************************************************************/

    /***************************************************************
     *PropertyUI 引用的控件
     ***************************************************************/
    @property({ group: { name: 'DEBUG', id: '2' }, type: Button, tooltip: `按钮组件` })
    private testButton: Button = undefined!;

    @property({ group: { name: 'DEBUG', id: '2' }, type: FontBubblePool, tooltip: `` })
    private testPool: FontBubblePool = undefined!;
    /****************************************************************************************************************
     * Lifecycle 生命周期相关方法
     ****************************************************************************************************************/
    protected onLoad(): void {
        super.onLoad();
        FontSingle.single.fontPool = this.testPool;

        // this.openPhysicsDebug();
        this.testButton.node.on(Button.EventType.CLICK, this.onTest, this);

        let values: number[] = this.createTestCharacter();

        let loadPromise = Promise.all([
            this.loadHero(values),
            this.loadLevel(this.createTestLevel()),
        ])

        loadPromise.then(
            (value) => {
                this.loadComplete();
            }, (error) => {
            }
        )
    }
    /****************************************************************************************************************
     * Public 公有方法
     ****************************************************************************************************************/

    /****************************************************************************************************************
     * private 私有方法
     ****************************************************************************************************************/
    /**
     * 开启物理调试
     */
    private openPhysicsDebug() {
        PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb |
            EPhysics2DDrawFlags.Pair |
            EPhysics2DDrawFlags.CenterOfMass |
            EPhysics2DDrawFlags.Joint |
            EPhysics2DDrawFlags.Shape;
    }


    private onTest() {
        if (!this.gameIng) {
            this.startGame();
            let ids = Array.from(CharacterManageSingle.single.teamSet.values())
            this.addHero(ids)
        }
    }

    /**
     * 创建测试关卡数据
     */
    private createTestLevel() {
        let level: LevelPO = {
            id: 1,
            waves: [
                { monsterId: 80001, time: 1, number: 3, lv: 1 },
                { monsterId: 80011, time: 10, number: 3, lv: 1 },
            ]
        }
        return level;
    }

    /**
     * 创建测试英雄数据
     * @returns 
     */
    private createTestCharacter() {
        let values: number[] = Array.from(CharacterManageSingle.single.teamSet.values())
        return values;
    }
    /****************************************************************************************************************
     * Property Get && Set 属性的 get && set 函数
     ****************************************************************************************************************/
}


